#include "mySqrt.h"

int mySqrt(int x)
{
	int left = 0;
	int right = x;
	int mid = 0; 

	if (x == 1)
	{
		return 1;
	}
	while (1)
	{
		mid = (left + right) / 2;
		if ((long long)mid * mid == x)
		{
			return mid;
		}
		else if ((long long)mid * mid > x)
		{
			right = mid;
		}
		else if ((long long)mid * mid < x)
		{
			left = mid;
		}

		if (right == left + 1)
		{
			return left;
		}
	}
	return 0;
}
